/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.pro.entity;

import org.hibernate.validator.constraints.Length;

import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.common.persistence.DataEntity;

/**
 * 项目日志Entity
 * @author fanqinglong
 * @version 2017-06-19
 */
public class ProLog extends DataEntity<ProLog> {
	
	private static final long serialVersionUID = 1L;
	private String module;		// 操作的模块（项目，任务组，任务）
	private String type;		// 操作类型
	private String moduleid;		// 模块的ID
	private String data;		// 数据
	private Project project;    // 所属项目
	private TaskGroup taskGroup;   //  所属任务组
	private String viewData;    // 显示的数据
	
	// 模块：项目
	public static final String PROJECT = "1";
	// 模块：任务组
	public static final String TASK_GROUP = "2";
	// 模块：任务
	public static final String TASK = "3";
	// 操作：新增
	public static final String CREATE = "1";
	// 操作：修改
	public static final String UPDATE = "2";
	// 操作：归档
	public static final String DELETE = "3";
	// 操作：分配成员
	public static final String ASSIGN_MEMBER = "4";
	// 操作：移除成员
	public static final String REMOVE_MEMBER = "5";
	
	
	public ProLog() {
		super();
	}

	public ProLog(String id){
		super(id);
	}

	@Length(min=0, max=64, message="操作的模块（项目，任务组，任务）长度必须介于 0 和 64 之间")
	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}
	
	@Length(min=0, max=10, message="操作类型长度必须介于 0 和 10 之间")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@Length(min=0, max=64, message="模块的ID长度必须介于 0 和 64 之间")
	public String getModuleid() {
		return moduleid;
	}

	public void setModuleid(String moduleid) {
		this.moduleid = moduleid;
	}
	
	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String getViewData() {
		if (ASSIGN_MEMBER.equals(type) || REMOVE_MEMBER.equals(type)) {
			return data;
		}
		if (PROJECT.equals(module)) {
			Project project = (Project) JsonMapper.fromJsonString(data, Project.class);
			return project.getName();
		}else if (TASK_GROUP.equals(module)) {
			TaskGroup taskGroup = (TaskGroup) JsonMapper.fromJsonString(data, TaskGroup.class);
			return taskGroup.getName();
		}else if (TASK.equals(module)) {
			ProjectTask projectTask = (ProjectTask) JsonMapper.fromJsonString(data, ProjectTask.class);
			return projectTask.getName();
		}
		return viewData;
	}

	public void setViewData(String viewData) {
		this.viewData = viewData;
	}

	public TaskGroup getTaskGroup() {
		return taskGroup;
	}

	public void setTaskGroup(TaskGroup taskGroup) {
		this.taskGroup = taskGroup;
	}
	
}